home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-18 | 6.1 KB | 229 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Part.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef DEFINES_K
- #include "Defines.k"
- #endif
-
- #ifndef BINDING_K
- #include "Binding.k"
- #endif
-
- #ifndef FWABOUT_H
- #include "FWAbout.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWSHAPE_H
- #include "FWShape.h"
- #endif
-
- //========================================================================================
- // Runtime informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment machack
- #endif
-
- //========================================================================================
- // CLASS CMacHackPart
- //========================================================================================
-
-
- FW_DEFINE_AUTO(CMacHackPart)
-
- //----------------------------------------------------------------------------------------
- // CMacHackPart::CMacHackPart
- //----------------------------------------------------------------------------------------
-
- CMacHackPart::CMacHackPart(ODPart* odPart):
- FW_CPart(odPart, FW_gInstance, kPartInfoID),
- fGeometry(cRectangle)
- {
- fShapes[0] = fShapes[1] = fShapes[2] = NULL;
- CreateShapes();
- }
-
- //----------------------------------------------------------------------------------------
- // CMacHackPart::~CMacHackPart
- //----------------------------------------------------------------------------------------
-
- CMacHackPart::~CMacHackPart()
- {
- DeleteShapes();
- }
-
- //----------------------------------------------------------------------------------------
- // CMacHackPart::Initialize
- //----------------------------------------------------------------------------------------
-
- void CMacHackPart::Initialize(Environment* ev)
- {
- FW_CPart::Initialize(ev);
-
- fPresentation = RegisterPresentation(ev, "Apple:Presentation:MacHack", TRUE);
-
- // ----- Initialize my menu -----
- GetMenuBar(ev)->InitializeFromResource(ev, kMenuBar);
- }
-
- //----------------------------------------------------------------------------------------
- // CMacHackPart::NewFrame
- //----------------------------------------------------------------------------------------
-
- FW_CFrame* CMacHackPart::NewFrame(Environment* ev,
- ODFrame* odFrame,
- FW_CPresentation* presentation,
- FW_Boolean fromStorage)
- {
- FW_UNUSED(presentation);
- FW_UNUSED(fromStorage);
-
- return FW_NEW(FW_CFrame, (ev, odFrame, presentation, this, kMacHackView));
- }
-
- //----------------------------------------------------------------------------------------
- // CMacHackPart::NewPartContent
- //----------------------------------------------------------------------------------------
-
- FW_CContent* CMacHackPart::NewPartContent(Environment* ev)
- {
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CMacHackPart::DoMenu
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CMacHackPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
- {
- FW_Boolean result = TRUE;
- ODCommandID commandID = theMenuEvent.GetCommandID(ev);
-
- switch (commandID)
- {
- case kODCommandAbout:
- ::FW_About(ev, this, kAbout);
- break;
-
- case cRectangle:
- case cOval:
- case cRoundRect:
- ChangeGeometry(ev, commandID);
- break;
-
- default:
- result = false;
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CMacHackPart::DoAdjustMenus
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CMacHackPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
- {
- if (hasMenuFocus)
- {
- menuBar->EnableAndCheckCommand(ev, cRectangle, TRUE, fGeometry == cRectangle);
- menuBar->EnableAndCheckCommand(ev, cOval, TRUE, fGeometry == cOval);
- menuBar->EnableAndCheckCommand(ev, cRoundRect, TRUE, fGeometry == cRoundRect);
- }
-
- return false;
- }
-
- //----------------------------------------------------------------------------------------
- // CMacHackPart::ChangeGeometry
- //----------------------------------------------------------------------------------------
-
- void CMacHackPart::ChangeGeometry(Environment* ev, ODCommandID geometry)
- {
- if (geometry != fGeometry)
- {
- fGeometry = geometry;
-
- DeleteShapes();
- CreateShapes();
-
- FW_CScreenContext sr(ev);
-
- FW_CRect bounds;
- for (short i = 0; i < 3; i++)
- {
- fShapes[i]->GetBounds(sr, bounds);
- fPresentation->Invalidate(ev, bounds);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMacHackPart::DeleteShapes
- //----------------------------------------------------------------------------------------
-
- void CMacHackPart::DeleteShapes()
- {
- for (short i = 0; i < 3; i++)
- delete fShapes[i];
-
- fShapes[0] = fShapes[1] = fShapes[2] = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CMacHackPart::CreateShapes
- //----------------------------------------------------------------------------------------
-
- void CMacHackPart::CreateShapes()
- {
- FW_CPlatformRect plfmRect(20, 50, 120, 150);
- FW_CRect rect(plfmRect);
-
- FW_CInk blue(FW_kRGBBlue);
- FW_CInk white(FW_kRGBWhite);
- FW_CInk red(FW_kRGBRed);
-
- switch (fGeometry)
- {
- case cRectangle:
- fShapes[0] = FW_NEW(FW_CRectShape, (rect, FW_kFill, blue));
- break;
- case cOval:
- fShapes[0] = FW_NEW(FW_COvalShape, (rect, FW_kFill, blue));
- break;
- case cRoundRect:
- fShapes[0] = FW_NEW(FW_CRoundRectShape, (rect, FW_CPoint(FW_IntToFixed(16), FW_IntToFixed(16)), FW_kFill, blue));
- break;
- }
-
-
- fShapes[1] = fShapes[0]->Copy();
- fShapes[1]->MoveShape(FW_IntToFixed(120), FW_kFixed0);
- fShapes[1]->SetInk(white);
-
- fShapes[2] = fShapes[1]->Copy();
- fShapes[2]->MoveShape(FW_IntToFixed(120), FW_kFixed0);
- fShapes[2]->SetInk(red);
- }
-